package com.leetcode.题库;

/**
 * @author 覃国强
 * @date 2022-03-12 20:22
 */
public class 题库_0035_搜索插入位置 {

  static
  class Solution {
    public int searchInsert(int[] nums, int target) {
      int left = 0;
      int right = nums.length - 1;

      while (left <= right) {
        int middle = (left + right) / 2;
        if (nums[middle] == target) {
          return middle;
        } else if (nums[middle] < target) {
          left = middle + 1;
        } else {
          right = middle - 1;
        }
      }

      return left;
    }
  }

}
